๐ฆธ Testing Converted Queries
You have already imported and converted your source queries, stored procedures or views into MongoDB queries. Relation Migrator allows you to go a step further, and verify the converted query by allowing you to compare results from the source query and converted query.
Prerequisiteโ
-
In order for Relational Migrator to run converted queries, you need to first install and run Query Runner.
-
The MongoDB query will be executed on your actual MongoDB database, so you must have completed migrating your data.
-
If you source data resides in the
public
schema in your PostgreSQL database, you may skip this step. Otherwise, you will need to add your source data schema into PostgreSQL's search path in order for the queries execute properly.Go to Manage Connections:
Edit your JDBC URI to include the search path. For example, if your source schema is
library
, addoptions=-c%20search_path%3Dlibrary
as a query parameter to your URI:Click Save and you can use the browser's back button to navigate back to the Query Converter page.
-
After which, you may expand the test query panel to begin executing your source query or converted query.
Executing queries for comparisonโ
- Select the source query you want to test on the left pane. As an example, we will select the
get_books_by_genre
stored procedure. - Convert the query to a MongoDB query if you have not done so, but note that the converted query may not always be correct.
- If it is a stored procedure, you will need to replace the placeholder parameter with a test value. In this example, we will replace it with
'Literature'
. - Click RUN SOURCE QUERY and RUN CONVERTED QUERY to execute the queries and compare the results.
- If the query results are different, check your MongoDB query. In this example, your MongoDB query should look like:
Also check that any changes your made to your MongoDB query are saved.
async function get_books_by_genre(db, genre_param) {
const result = await db.collection('books').aggregate([
{
$match: {
'genre': genre_param
}
},
{
$project: {
title: 1
}
}
]).toArray();
return result;
}